package main

import (
	"time"
	"fmt"
)

//Go的内置计时器功能
func main() {

	timer1 := time.NewTimer(2 * time.Second)

	<-timer1.C
	fmt.Println("Timer 1 expired")

	//第一个计时器在启动程序后会过期〜2秒，但第二个计时器应该在有机会到期之前停止
	timer2 := time.NewTimer(time.Second)
	go func() {
		<-timer2.C
		fmt.Println("Timer 2 expired")
	}()
	stop2 := timer2.Stop()
	if stop2 {
		fmt.Println("Timer 2 stopped")
	}
}
